// ornk.txt
// Script for ornk
// Memory Cells:
//   Cell 0 - If 0, fidgets a little. If 1, a lot. If 2, follows char in cell 1.
//       if 3 no move
//	 Cell 1 - Ornk this one follows

begincreaturescript;

variables;

short fidget_chance;

body;

beginstate INIT_STATE;
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	if ((is_combat() == FALSE) && (am_i_doing_action() == FALSE) && (get_ran(1,0,100) < 15)) {	
		run_char_animation(5,1,75);	
		pc_heard_sound_delay(138,650);	
		set_state(4);
		}
	if ((is_combat() == FALSE) && (am_i_doing_action() == FALSE) && (get_ran(1,0,100) < 8)) 
		pc_heard_sound(139);
		
	if (get_memory_cell(0) < 2) {
		if (get_memory_cell(0) == 0)
			fidget_chance = 25;
			else fidget_chance = 60;
		if (my_dist_from_start() >= 12) {
			if (get_ran(1,1,100) < 40) 
				return_to_start(ME,1);
			}
			else fidget(ME,fidget_chance);
		}
		else if (get_memory_cell(0) == 2) {
			if (get_memory_cell(1) >= 8) {
				if (char_ok(get_memory_cell(1)))
					maintain_dist_to_char(ME,get_memory_cell(1),4);
					else fidget(ME,8);
				}
				else fidget(ME,8);
			}
			
	if (am_i_doing_action() == FALSE)
		end_combat_turn();				

break;

beginstate TALKING_STATE;
	print_str("This particular piece of livestock seems friendly enough, but it");
	print_str("  has neither the inclination nor the ability to carry on a conversation");
	print_str("  with you.");
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate 4; // munching
	if (am_i_doing_action() == FALSE)
		set_state(START_STATE);
break;
